package com.qf.controller;

import com.qf.entity.User;
import com.qf.service.UserService;
import com.qf.service.impl.userServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/*
杨威
2021/9/24
14:06
*/
@WebServlet("/checkOldPwd")
public class CheckOldPwdController extends HttpServlet {
    UserService userService=new userServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String oldPwd = request.getParameter("oldPwd");
        User user = (User) request.getSession().getAttribute("user");
        User user1 = userService.login(user.getUserName(), oldPwd);
        PrintWriter writer = response.getWriter();
        if(user1!=null){
            request.getSession().setAttribute("user",user1);
            writer.println(1);
        }else {
            writer.println(0);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
